package com.chinaoryx;

import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: hyman.zhang
 * Date: 12-1-27
 * Time:
 * To change this template use File | Settings | File Templates.
 */
public class TaskObject {
    private String taskId;
    private int interval;
    private Thread thread = null;
    MyThread myThread = null;
    private Map<String, Object> parameterMap = null;
    private String taskClassName = null;
    
    public void newThread() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        this.myThread = new MyThread(this.taskId, this.interval*1000, this.taskClassName, this.parameterMap);
        this.thread = new Thread(this.myThread);
    }

    public String getTaskClassName() {
        return taskClassName;
    }

    public void setTaskClassName(String taskClassName) {
        this.taskClassName = taskClassName;
    }

    public MyThread getMyThread() {
        return myThread;
    }





    


    public String getTaskId() {
        return taskId;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public int getInterval() {
        return interval;
    }

    public void setInterval(int interval) {
        this.interval = interval;
    }

    public Thread getThread() {
        return thread;
    }


    public void setParameterMap(Map parameterMap) {
        this.parameterMap = parameterMap;
    }
    
    public String getStatus() {
        String status = "";

        status = status + ":";
        if (this.thread != null) {
//            this.thread.
           if ( this.thread.isAlive()) {
               status += "true";
           } else {
               status += "false";
           }
            status += "/";
           if (this.thread.isInterrupted()) {
               status += "true";
           } else {
               status  += "false";
           }
           status += "/";
           Thread.State state = this.thread.getState();
           if (state != null) {
               status += state.name();
           }
        }
        return status;
    }
}
